<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>style_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_testing_style_style_test.js.html">style_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2011 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.testing.styleTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.testing.styleTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.dom&#39;);
<a name="line19"></a>goog.require(&#39;goog.style&#39;);
<a name="line20"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line21"></a>goog.require(&#39;goog.testing.style&#39;);
<a name="line22"></a>
<a name="line23"></a>var div1;
<a name="line24"></a>var div2;
<a name="line25"></a>
<a name="line26"></a>function setUp() {
<a name="line27"></a>  var createDiv = function(color) {
<a name="line28"></a>    var div = goog.dom.createDom(
<a name="line29"></a>        &#39;div&#39;,
<a name="line30"></a>        {
<a name="line31"></a>          style: &#39;position:absolute;top:0;left:0;&#39; +
<a name="line32"></a>              &#39;width:200px;height:100px;&#39; +
<a name="line33"></a>              &#39;background-color:&#39; + color,
<a name="line34"></a>          innerHTML: &#39;abc&#39;
<a name="line35"></a>        });
<a name="line36"></a>    document.body.appendChild(div);
<a name="line37"></a>    return div;
<a name="line38"></a>  };
<a name="line39"></a>
<a name="line40"></a>  div1 = createDiv(&#39;#EEE&#39;);
<a name="line41"></a>  div2 = createDiv(&#39;#F00&#39;);
<a name="line42"></a>}
<a name="line43"></a>
<a name="line44"></a>
<a name="line45"></a>function tearDown() {
<a name="line46"></a>  if (div1.parentNode)
<a name="line47"></a>    div1.parentNode.removeChild(div1);
<a name="line48"></a>  if (div2.parentNode)
<a name="line49"></a>    div2.parentNode.removeChild(div2);
<a name="line50"></a>
<a name="line51"></a>  div1 = null;
<a name="line52"></a>  div2 = null;
<a name="line53"></a>}
<a name="line54"></a>
<a name="line55"></a>
<a name="line56"></a>function testIsVisible() {
<a name="line57"></a>  assertTrue(&#39;The div should be detected as visible.&#39;,
<a name="line58"></a>             goog.testing.style.isVisible(div1));
<a name="line59"></a>
<a name="line60"></a>  // Tests with hidden element
<a name="line61"></a>  goog.style.setElementShown(div1, false /* display */);
<a name="line62"></a>  assertFalse(&#39;The div should be detected as not visible.&#39;,
<a name="line63"></a>              goog.testing.style.isVisible(div1));
<a name="line64"></a>}
<a name="line65"></a>
<a name="line66"></a>function testIsOnScreen() {
<a name="line67"></a>  var el = document.createElement(&#39;div&#39;);
<a name="line68"></a>  document.body.appendChild(el);
<a name="line69"></a>
<a name="line70"></a>  var dom = goog.dom.getDomHelper(el);
<a name="line71"></a>  var winScroll = dom.getDocumentScroll();
<a name="line72"></a>  var winSize = dom.getViewportSize();
<a name="line73"></a>
<a name="line74"></a>  el.style.position = &#39;absolute&#39;;
<a name="line75"></a>  goog.style.setSize(el, 100, 100);
<a name="line76"></a>
<a name="line77"></a>  goog.style.setPosition(el, winScroll.x, winScroll.y);
<a name="line78"></a>  assertTrue(&#39;An element fully on the screen is on screen.&#39;,
<a name="line79"></a>      goog.testing.style.isOnScreen(el));
<a name="line80"></a>
<a name="line81"></a>  goog.style.setPosition(el, winScroll.x - 10, winScroll.y - 10);
<a name="line82"></a>  assertTrue(
<a name="line83"></a>      &#39;An element partially off the top-left of the screen is on screen.&#39;,
<a name="line84"></a>      goog.testing.style.isOnScreen(el));
<a name="line85"></a>
<a name="line86"></a>  goog.style.setPosition(el, winScroll.x - 150, winScroll.y - 10);
<a name="line87"></a>  assertFalse(
<a name="line88"></a>      &#39;An element completely off the top of the screen is off screen.&#39;,
<a name="line89"></a>      goog.testing.style.isOnScreen(el));
<a name="line90"></a>
<a name="line91"></a>  goog.style.setPosition(el, winScroll.x - 10, winScroll.y - 150);
<a name="line92"></a>  assertFalse(
<a name="line93"></a>      &#39;An element completely off the left of the screen is off screen.&#39;,
<a name="line94"></a>      goog.testing.style.isOnScreen(el));
<a name="line95"></a>
<a name="line96"></a>  goog.style.setPosition(el, winScroll.x + winSize.width + 1, winScroll.y);
<a name="line97"></a>  assertFalse(
<a name="line98"></a>      &#39;An element completely off the right of the screen is off screen.&#39;,
<a name="line99"></a>      goog.testing.style.isOnScreen(el));
<a name="line100"></a>
<a name="line101"></a>  goog.style.setPosition(el, winScroll.x, winScroll.y + winSize.height + 1);
<a name="line102"></a>  assertFalse(
<a name="line103"></a>      &#39;An element completely off the bottom of the screen is off screen.&#39;,
<a name="line104"></a>      goog.testing.style.isOnScreen(el));
<a name="line105"></a>
<a name="line106"></a>  goog.style.setPosition(el, winScroll.x + winSize.width - 10, winScroll.y);
<a name="line107"></a>  assertTrue(
<a name="line108"></a>      &#39;An element partially off the right of the screen is on screen.&#39;,
<a name="line109"></a>      goog.testing.style.isOnScreen(el));
<a name="line110"></a>
<a name="line111"></a>  goog.style.setPosition(el, winScroll.x, winScroll.y + winSize.height - 10);
<a name="line112"></a>  assertTrue(
<a name="line113"></a>      &#39;An element partially off the bottom of the screen is on screen.&#39;,
<a name="line114"></a>      goog.testing.style.isOnScreen(el));
<a name="line115"></a>
<a name="line116"></a>  var el2 = document.createElement(&#39;div&#39;);
<a name="line117"></a>  el2.style.position = &#39;absolute&#39;;
<a name="line118"></a>  goog.style.setSize(el2, 100, 100);
<a name="line119"></a>  goog.style.setPosition(el2, winScroll.x, winScroll.y);
<a name="line120"></a>  assertFalse(&#39;An element not in the DOM is not on screen.&#39;,
<a name="line121"></a>              goog.testing.style.isOnScreen(el2));
<a name="line122"></a>}
<a name="line123"></a>
<a name="line124"></a>function testHasVisibleDimensions() {
<a name="line125"></a>  goog.style.setSize(div1, 0, 0);
<a name="line126"></a>  assertFalse(&#39;0x0 should not be considered visible dimensions.&#39;,
<a name="line127"></a>              goog.testing.style.hasVisibleDimensions(div1));
<a name="line128"></a>  goog.style.setSize(div1, 10, 0);
<a name="line129"></a>  assertFalse(&#39;10x0 should not be considered visible dimensions.&#39;,
<a name="line130"></a>              goog.testing.style.hasVisibleDimensions(div1));
<a name="line131"></a>  goog.style.setSize(div1, 10, 10);
<a name="line132"></a>  assertTrue(&#39;10x10 should be considered visible dimensions.&#39;,
<a name="line133"></a>             goog.testing.style.hasVisibleDimensions(div1));
<a name="line134"></a>  goog.style.setSize(div1, 0, 10);
<a name="line135"></a>  assertFalse(&#39;0x10 should not be considered visible dimensions.&#39;,
<a name="line136"></a>              goog.testing.style.hasVisibleDimensions(div1));
<a name="line137"></a>}
<a name="line138"></a>
<a name="line139"></a>function testIntersects() {
<a name="line140"></a>  // No intersection
<a name="line141"></a>  goog.style.setPosition(div1, 0, 0);
<a name="line142"></a>  goog.style.setPosition(div2, 500, 500);
<a name="line143"></a>  assertFalse(&#39;The divs should not be determined to itersect.&#39;,
<a name="line144"></a>              goog.testing.style.intersects(div1, div2));
<a name="line145"></a>
<a name="line146"></a>  // Some intersection
<a name="line147"></a>  goog.style.setPosition(div1, 0, 0);
<a name="line148"></a>  goog.style.setPosition(div2, 50, 50);
<a name="line149"></a>  assertTrue(&#39;The divs should be determined to itersect.&#39;,
<a name="line150"></a>             goog.testing.style.intersects(div1, div2));
<a name="line151"></a>
<a name="line152"></a>  // Completely superimposed.
<a name="line153"></a>  goog.style.setPosition(div1, 0, 0);
<a name="line154"></a>  goog.style.setPosition(div2, 0, 0);
<a name="line155"></a>  assertTrue(&#39;The divs should be determined to itersect.&#39;,
<a name="line156"></a>             goog.testing.style.intersects(div1, div2));
<a name="line157"></a>}
</pre>


</body>
</html>
